

import { WX_AD_CONFIG, Sdk_Platform } from '../../frame/constants';
cc.Class({
    extends: cc.Component,

    properties: {
        leftAd: cc.Node,
        rightAd: cc.Node,
    },
    start() {

    },

    // update (dt) {},

    initPage() {
    },

    updatePage() {
        this.adSwitch(true)
    },

    closeUI() {
        this.leftAd.getChildByName('adIcon').getComponent('adIcon').clear()
        he.pool.putElement('adIcon', this.leftAd.getChildByName('adIcon'))

        this.rightAd.getChildByName('adIcon').getComponent('adIcon').clear()
        he.pool.putElement('adIcon', this.rightAd.getChildByName('adIcon'))
    },

    adSwitch(status) {
        if (status) {
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    if (!common.showAd) return
                    he.ad.getTdAdJson(WX_AD_CONFIG.tmIcon[5], this.creatAdIcon.bind(this))
                    break
            }
        } else {
            //  关掉广告
        }
    },

    creatAdIcon(config) {
        if (config.isOpen) {
            let pre = he.pool.getElement('adIcon')
            pre.position = cc.Vec2.ZERO
            pre.parent = this.leftAd
            pre.opacity = 255
            let spt = pre.getComponent('adIcon')
            spt.init(config.creatives[0], true, true, 0.8)
            if(config.creatives[1]){
                let pre2 = he.pool.getElement('adIcon')
                pre2.position = cc.Vec2.ZERO
                pre2.parent = this.rightAd
                pre2.opacity = 255
                let spt2 = pre2.getComponent('adIcon')
                spt2.init(config.creatives[1], true, true, 0.8)
            }
           
        }
    },

});
